<title>角色列表</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>角色管理</cite></a>
        <a><cite>角色列表</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="lay-userlist-search-view">
            <div class="layui-form-item">
               <div class="layui-inline">
                    角色名：
                </div>
                <div class="layui-inline">
                    <input type="text" name="name" placeholder="请输入用户登录名" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-radius  layuiadmin-btn-admin" lay-submit
                        lay-filter="LAY-user-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <!-- TABLE HEAD TOOLS BAR -->
            <script type="text/html" id="my-table-tool" style="padding-bottom: 10px;">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm layuiadmin-btn-admin" lay-event="adduser">添加</button>
                    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="multipledel">删除</button>
                </div>
            </script>
            <!-- TBABLE -->
            <table id="LAY-userlist-tableid" lay-filter="LAY-userlist-table"></table>
            <!-- TABLE MY TOOLS BAR -->
            <script type="text/html" id="table-toolbar">
                <button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>
                <button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</button>
                <button class="layui-btn layui-btn-primary layui-btn-xs" lay-event="menuset">权限设置</button>
             </script>
        </div>
    </div>
</div>

<script>
    layui.use('xrolelist', layui.factory('xrolelist')).use(['admin', 'useradmin', 'table', 'setter', 'excel'], function () {
        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , table = layui.table
            , setter = layui.setter
            , excel = layui.excel
            , form = layui.form;

        form.render(null, 'lay-userlist-search-view');

        //搜索
        form.on('submit(LAY-user-search)', function (data) {
            var field = data.field;

            //执行重载
            table.reload('LAY-userlist-tableid', {
                page: { curr: 1 },
                where: {
                    queryparams: field
                }
            });
        });

        //自定义按钮事件 data-type， 需要最后手动绑定
        var active = {
            excelout: function () {
                var data = [{ name: 'wang', age: 18, sex: '男' }, { name: 'layui', age: 3, sex: '女' }];
                // 1. 数组头部新增表头
                data.unshift({ name: '用户名', sex: '男', age: '年龄' });
                // 2. 如果需要调整顺序，请执行梳理函数
                var data = excel.filterExportData(data, [
                    'name',
                    'sex',
                    'age',
                ]);
                // 3. 执行导出函数，系统会弹出弹框
                excel.exportExcel({
                    sheet1: data
                }, '导出接口数据.xlsx', 'xlsx');
            }
        };

        //根据class 手动绑定 data-type click事件
        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>